/**
 * 地图操作工具类
 * 与业务无关的地图操作方法
 */

import L from "leaflet";
export default class MapTool {
  constructor(map) {
    this.map = map;
  }

  /** 创建地图标记 */
  addMarker(center, icon, options) {
    options = Object.assign({
      icon
    }, options);
    return L.marker(center, options).addTo(this.map);
  }

  /** 创建带弹窗的标记 */
  addMarkerWithPopup(center, popup, options = {}) {
    options = Object.assign({
      icon: this.buildIcon()
    }, options);
    let marker = L.marker(center, options).bindPopup(popup).addTo(this.map);
    return marker;
  }

  /** 设置中心点 */
  setCenter(point, level) {
    this.map.flyTo(point, level, { animate: false });
  }

  /** 设置地图级别 */
  setLevel(level) {
    this.map.setZoom(level);
  }

}